const fs = require('fs')
const path = require('path')
function dfs(dir) {
    const result = []
    if (fs.statSync(dir).isDirectory()) {
        const dirs = fs.readdirSync(path.resolve(__dirname, dir))
        dirs.forEach(filename => {
            const curFilePath = dir + path.sep + filename
            if (fs.statSync(curFilePath).isDirectory()) {
                const block = {name: filename, children: []}
                block.children.push(...dfs(curFilePath))
                result.push(block)
            } else {
                result.push({name: filename})
            }
        })
    }
    return result
}
let result = dfs(path.resolve(__dirname, '1'))
console.log(JSON.stringify(result));